import { nextTick, Ref } from "vue";

export const useForm = (formRef: Ref) => {
  const updateFields = async (data: any, reset?: Boolean) => {
    await nextTick();
    formRef.value?.updateFields(data, reset);
  };

  const validateFields = () => {
    return formRef.value?.validateFields();
  };

  const resetFields = async () => {
    await nextTick();
    return formRef.value?.resetFields();
  };

  const getFields = async () => {
    await nextTick();
    return formRef.value?.getFields();
  };

  return { updateFields, validateFields, resetFields, getFields };
};
